package org.example.utils;

import org.example.pojo.*;
import org.springframework.scheduling.annotation.Schedules;

import java.util.ArrayList;
import java.util.List;

public class Tool {
    List<Teacher> teachers=new ArrayList<>();//教师
    List<Course> courses=new ArrayList<>();//课程
    List<Classes> classes=new ArrayList<>();//班级
    List<Plan> plan=new ArrayList<>();//课程计划

    public Tool() {
    }

    public int[] findPri(int courseno){
        int[] t=new int[2];
        for(Course c:courses){
            if(c.getCourseno()==courseno) {
                t[0] = c.getPri();
                t[0] = c.getType();
                return t;//返回课程的优先级
            }
        }
        return t;
    }

    public int findCtype(int courseno){//查找课程的类型
        for(Course c:courses){
            if(c.getCourseno()==courseno) {
                return c.getNature();
            }
        }
        return 0;
    }

    public int findClassP(int classno) {//返回班级人数
        for (Classes c : classes) {
            if (c.getClassno() == classno)
                return c.getPeople();
        }
        return 0;
    }

    public List<Integer> findTeacherNo(int courseno) {//返回教这门课的老师
        for(Course c:courses){
            if(c.getCourseno()==courseno) {
                return c.getTeacherNo();//返回老师
            }
        }
        return null;
    }

    public Plan findPlan(int No){
        for(Plan p:plan){
            if(p.getMajorno()==No)
                return p;
        }
        return null;
    }

    public boolean checkTeacher(int TeacherNo,int x) {//查看老师在x时间是否有课,false没课
        for (Teacher t : teachers) {
            if (t.getAccount() == TeacherNo)
//                System.out.println("找到教师、、、、、、"+t.getTeacherTime(x));
                return t.getTeacherTime(x);
        }
//        System.out.println("没找到教师................");
        return true;
    }

    public void setTeacher(int TeacherNo,int x) {//设置教师在x时间有课
        for (Teacher t : teachers) {
            if (t.getAccount() == TeacherNo){
                t.setTeacherTime(x,true);
                return ;
            }
        }
    }

    public void addPiece(PieceSchedule pieceSchedules[],List<Schedule> schedules){
        int i=0;
        for(Schedule s:schedules){
            for(PieceSchedule p:s.getPieceSchedules()){
                pieceSchedules[i++]=p;
            }
        }
        bubble(pieceSchedules);
    }

    public void bubble(PieceSchedule pieceSchedules[]){//排序
        for (int i = 0; i < pieceSchedules.length - 1; i++) {
            for (int j = 0; j < pieceSchedules.length-1-i; j++) {
                if(pieceSchedules[j].getFinalpri()<pieceSchedules[j+1].getFinalpri()){
                    PieceSchedule temp=pieceSchedules[j];
                    pieceSchedules[j]=pieceSchedules[j+1];
                    pieceSchedules[j+1]=temp;
                }
            }
        }
    }

    public List<Classes> getClasses() {
        return classes;
    }

    public void setClasses(List<Classes> classes) {
        this.classes = classes;
    }

    public List<Course> getCourses() {
        return courses;
    }

    public void setCourses(List<Course> courses) {
        this.courses = courses;
    }

    public List<Teacher> getTeachers() {
        return teachers;
    }

    public void setTeachers(List<Teacher> teachers) {
        this.teachers = teachers;
    }

    public List<Plan> getPlan() {
        return plan;
    }

    public void setPlan(List<Plan> plan) {
        this.plan = plan;
    }

    public String checkCourseTypeString(int Type){
        if(Type==12) return "选修课";
        if(Type==14) return "公共课";
        if(Type==16) return "专业课";
        if(Type==18) return "必修课";
        return null;
    }

    public int checkCourseTypeint(String Type){
        if(Type.equals("选修课")) return 12;
        if(Type.equals("公共课")) return 14;
        if(Type.equals("专业课")) return 16;
        if(Type.equals("必修课")) return 18;
        return 0;
    }

    public int checkCourseNature(String Type){
        if(Type.equals("实践课")) return 1;
        if(Type.equals("理论课")) return 0;
        return 0;
    }

    public String checkCourseChracter(int Type){
        if(Type==0) return "理论课";
        if(Type==1) return "实践课";
        return null;
    }

    public int checkTeacherint(String Type){
        if(Type.equals("助教")) return 0;
        if(Type.equals("初级")) return 1;
        if(Type.equals("中级")) return 2;
        if(Type.equals("高级")) return 3;
        if(Type.equals("副教授")) return 4;
        if(Type.equals("教授")) return 5;
        return 0;
    }

    public String checkTeacherString(int Type){
        if(Type==0) return "助教";
        if(Type==1) return "初级";
        if(Type==2) return "中级";
        if(Type==3) return "高级";
        if(Type==4) return "副教授";
        if(Type==5) return "教授";
        return null;
    }

}
